(require 'asdf)
(asdf:operate 'asdf:load-op :png)

(defun mangle (fun infile outfile)
  (let ((image (png:decode-file infile)))
    (png:encode-file (funcall fun image)
		     outfile)))

(defun make-pixel-filter (fun)
  (lambda (image)
    (dotimes (i (array-dimension image 0) image)
      (dotimes (j (array-dimension image 1))
	(setf (aref image i j)
	      (funcall fun (aref image i j)))))))

(defun lognot-filter (image)
  (dotimes (i (array-dimension image 0) image)
    (dotimes (j (array-dimension image 1))
      (setf (aref image i j)
	    (lognot (aref image i j))))))

;;  There is no perceptible difference in performance betweeb these two
(time (mangle (make-pixel-filter #'lognot) "logo.png" "lognot.png"))
(time (mangle #'lognot-filter "logo.png" "lognot.png"))